﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="riigiloivType_v4", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(RiigiloivTypeV4))]
    public class RiigiloivTypeV4Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IRiigiloivTypeV4 clazz;
        
        public RiigiloivTypeV4Serializer(IRiigiloivTypeV4 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("summa");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "decimal");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDecimal(((decimal)(clazz.Summa))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("valuuta");
            if (clazz.Valuuta!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Valuuta))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Valuuta");
            }
            Writer.WriteEndElement();
            if (clazz.Viitenumber!=null) {
                Writer.WriteStartElement("viitenumber");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Viitenumber))).ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("selgitus");
            if (clazz.Selgitus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Selgitus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Selgitus");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="summa") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>riigiloivType_v4>summa");
                }
                clazz.Summa = new global::Xtee.Core.Schema.XsdDecimal(Reader.ReadElementString("summa")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>riigiloivType_v4>summa", Reader.LocalName);
            }
            if (Reader.LocalName=="valuuta") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>riigiloivType_v4>valuuta");
                }
                clazz.Valuuta = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("valuuta")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>riigiloivType_v4>valuuta", Reader.LocalName);
            }
            if (Reader.LocalName=="viitenumber") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>riigiloivType_v4>viitenumber");
                }
                clazz.Viitenumber = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("viitenumber")).Value;
            }
            if (Reader.LocalName=="selgitus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>riigiloivType_v4>selgitus");
                }
                clazz.Selgitus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("selgitus")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>riigiloivType_v4>selgitus", Reader.LocalName);
            }
        }
    }
}
